package com.beta.cust.bind.webapi.controller;

import com.beta.cat.utils.JsonUtil;
import com.beta.cust.bind.api.request.CrmQueryReq;
import com.beta.cust.bind.api.request.VerificationCodeReq;
import com.beta.cust.bind.api.service.IRpcCommonService;
import com.beta.cust.bind.webapi.constant.ResultCode;
import com.beta.cust.bind.webapi.request.VerificationCodeRequest;
import com.beta.elephant.vo.ResultVO;
import com.beta.platform.rest.auth.LoginAccountDetail;
import com.beta.platform.rest.auth.LoginAccountSecurity;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * @Auther: pcc
 * @Date: 2024/3/28 14:23
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping
public class CommonController {

    @DubboReference
    private IRpcCommonService rpcCommonService;

    @GetMapping("/verification/code")
    public ResultVO sendVerificationCode(VerificationCodeRequest req) {
        VerificationCodeReq verificationCodeReq = new VerificationCodeReq();
        verificationCodeReq.setPhone(req.getPhone());
        LoginAccountDetail loginAccountDetail = LoginAccountSecurity.getLoginAccountDetail();
        log.info("verificationCode signet {}",JsonUtil.toJson(loginAccountDetail));
        verificationCodeReq.setUserId(loginAccountDetail.getThirdUserInfo().getUserId());
        ResultVO resp = rpcCommonService.sendVerificationCode(verificationCodeReq);
        if (resp.getCode() != ResultCode.SUCCESS.getCode()) {
            return ResultVO.failure(resp.getCode(), resp.getMsg());
        }
        return resp;
    }

    @GetMapping("/query/crm")
    public ResultVO<Map<String, String>> queryCrm(CrmQueryReq latestReq) {
        log.info("queryCrm param:{}",JsonUtil.toJson(latestReq));
        return rpcCommonService.testCrmInterface(latestReq);
    }
}
